import java.util.Scanner;

/**
 * @author caesar
 * @date 2025/6/30
 * @apiNote
 */
//输入年月日，直到符合要求为止
public class KeywordTest {
    public static void main(String[] args) {
        int year, month, day;
        Scanner input = new Scanner(System.in);
        //判断年
        while (true) {
            System.out.println("请输入年份（必须为正整数）：");
            year = input.nextInt();
            if (year <= 0) {
                System.out.println("输入错误，请重新输入！");
            } else {
                break;
            }
        }
        //判断月
        while (true) {
            System.out.print("请输入月份（1-12）：");
            month = input.nextInt();
            if (month < 1 || month > 12) {
                System.out.println("输入错误，请重新输入！");
            } else {
                break;
            }
        }

        int totaldays = 0;
        if(month == 2){
            totaldays = year%4 == 0 && year%100 != 0 || year%400 == 0 ? 29 : 28;
        }else if(month == 4 || month == 6 || month == 9 || month == 11 ){
            totaldays = 30;
        }else{
            totaldays = 31;
        }
        //判断天
        while (true) {
            System.out.print("请输入日期（1-31）：");
            day = input.nextInt();
            if (day < 1 || day > 31 || day > totaldays) {
                System.out.println("输入错误，请重新输入！");
            }
            else {
                System.out.println("输入的日期是：" + year + "年" + month + "月" + day + "日");
                break;
            }

        }

    }
}
